﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;


namespace WpfApplication4
{

    public interface CommunicatorInterface
    {
        byte this[int addr]
        {
            get;
            set;
        }

    }

    
    /// <summary>
    /// Interaction logic for Communicator.xaml
    /// </summary>
    public partial class Communicator : System.Windows.Controls.Image, CommunicatorInterface 
    {

        private struct CommunicatorValue
        {
            public CommunicatorInterface resource;
            public int addr;
        }
        private List<CommunicatorInterface> resources = new List<CommunicatorInterface>();
        List<CommunicatorValue> map = new List<CommunicatorValue>();
        


        private Communicator_Window win = new Communicator_Window();
        public Communicator()
        {
            InitializeComponent();
            // Register mouse click event
            this.MouseDown += new MouseButtonEventHandler(this.my_MouseDown); 

            //Uri ur = new Uri("c:/64.jpg", UriKind.RelativeOrAbsolute);
            //this.Source = new System.Windows.Media.Imaging.BitmapImage(ur);
            
        }


        private void my_MouseDown(object sender, MouseEventArgs e)
        {
            win.Show();
        }

        public byte this[int addr]
        {
            get {
                return map[addr].resource[map[addr].addr];
            }
            set {
                map[addr].resource[map[addr].addr] = value;
            }
        }

        public void registerResource(CommunicatorInterface res)
        {
            resources.Add(res);
        }

        public void addMapping(int addr, CommunicatorInterface res, int resAddr)
        {
            CommunicatorValue temp = new CommunicatorValue();
            temp.addr = resAddr;
            temp.resource = res;
            map.Insert(addr, temp);
        }

    }
}
